
             
/**
 * 
 *
 * @File name:  QueryTFixedAssetsByPagerAction.java 
 * @Create on:  2011-10-30 20:01:343
 * @Author   :  陈伟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
        
package com.boho.estates.report.action;

            
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.xvolks.jnative.JNative;
import org.xvolks.jnative.Type;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import com.boho.common.ContentTypeUtils;
import com.boho.common.IoUtil;
import com.boho.estates.po.*;
import cn.boho.framework.actions.ActionImp;
import cn.boho.framework.context.ActionContext;
import cn.boho.framework.po.POUtils;
import cn.boho.framework.service.FileServerService;
import cn.boho.framework.service.MessageService;
import cn.boho.framework.exception.UserOperationException;
import cn.boho.framework.utils.DateUtils;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.po.ComboPager;
import cn.boho.framework.po.Pager;
            
        
import com.boho.estates.report.dao.TFixedAssetsDao;
import com.boho.estates.report.service.TFixedAssetsService;

public class PrintBarcodeAction extends ActionImp {
	
	String barcode = "";
	@Override
	protected void doException(ActionContext atx, Exception ex) {
		
		if (!(ex instanceof UserOperationException)) {
			atx.setErrorContext("BOHO_COMMON_1001", "打印条码出现异常"+ex.getMessage(),"【系统后台用户】", ex);
		}
	}
	@Override
	protected int performExecute(ActionContext atx) throws Exception {
		JNative sendcommand = null;
		JNative clearbuffer = null;
		JNative setup = null;
		JNative windowsfont = null;
		JNative printlabel = null;
		JNative openport = null;
		JNative closeport = null;
		 try {
			clearbuffer = new JNative("TSCLib.dll", "clearbuffer");
			sendcommand = new JNative("TSCLib.dll", "sendcommand");
			setup = new JNative("TSCLib.dll", "setup");			
			windowsfont = new JNative("TSCLib.dll", "windowsfont");
			printlabel = new JNative("TSCLib.dll", "printlabel");
			openport = new JNative("TSCLib.dll", "openport");
			closeport = new JNative("TSCLib.dll", "closeport"); 
			 
			 
			 openport.setParameter(0, Type.STRING, "TSC TTP-244CE");
			 openport.invoke();
			 
			 clearbuffer.invoke();
			 
			 sendcommand.setParameter(0, Type.STRING,"DIRECTION 1");
			 sendcommand.invoke();
			 
			 setup.setParameter(0, Type.STRING,"60");
			 setup.setParameter(1, Type.STRING,"35");
			 setup.setParameter(2, Type.STRING,"4");
			 setup.setParameter(3, Type.STRING,"9");
			 setup.setParameter(4, Type.STRING,"0");
			 setup.setParameter(5, Type.STRING,"2");
			 setup.setParameter(6, Type.STRING,"0");
			 setup.invoke();
			 
			 
			 windowsfont.setParameter(0, Type.INT,"60");
			 windowsfont.setParameter(1, Type.INT,"50");
			 windowsfont.setParameter(2, Type.INT,"30");
			 windowsfont.setParameter(3, Type.INT,"0");
			 windowsfont.setParameter(4, Type.INT,"2");
			 windowsfont.setParameter(5, Type.INT,"0");
			 windowsfont.setParameter(6, Type.STRING,"黑体");
			 windowsfont.setParameter(7, Type.STRING,barcode);
			 windowsfont.invoke();
			 
			 sendcommand.setParameter(0, Type.STRING,"PDF417 30,80,400,200,0,\""+barcode+"\"");
			 sendcommand.invoke();
			 
			 printlabel.setParameter(0, Type.STRING,"1");
			 printlabel.setParameter(1, Type.STRING,"1");
			 printlabel.invoke();
			 
			 closeport.invoke();
			 
			 
		 } catch(IllegalAccessException e){
			 UserOperationException uoe = new UserOperationException();
			 atx.setErrorContext("FSTI_COMMON_1004", "d",uoe);
			 throw uoe;
		 }	 
		 finally {
			 if (clearbuffer != null) {
					try {
						clearbuffer.dispose();
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
				if(sendcommand!=null){
					try {
						sendcommand.dispose();
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
				if(setup!=null){
					try {
						setup.dispose();
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
				if(windowsfont!=null){
					try {
						windowsfont.dispose();
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
				if(printlabel!=null){
					try {
						printlabel.dispose();
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
				if(openport!=null){
					try {
						openport.dispose();
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
				if(closeport!=null){
					try {
						closeport.dispose();
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
          }
		
		return 1;

	}
	@Override
	protected int verifyParameters(ActionContext atx) throws Exception {
		barcode = atx.getStringValue("BARCODE");
		return 1;
	}
	
	
}
